<?php

namespace App\Models\Game\Platform\Doc;

use App\Models\Game\Model;
use App\Models\Traits\Game\LogsActivity;
use Illuminate\Database\Eloquent\Relations\HasOne;

class Tree extends Model
{
    use LogsActivity;

    /**
     * 数据表名称
     *
     * @var string
     */
    protected $table = 't_plat_doc_tree';

    /**
     * 查询后隐藏的字段
     *
     * @var array
     */
    protected $hidden = [
        'created',
        'updated'
    ];

    /**
     * 可以批量赋值的字段
     *
     * @var array
     */
    protected $fillable = [
        'parent_id',
        'path',
        'name',
        'sort'
    ];

    /**
     * 获得内容详情
     *
     * @return HasOne
     */
    public function detail(): HasOne
    {
        return $this->hasOne(Detail::class, 'tree_id', 'id');
    }

    /**
     * 查询所有正常数据
     *
     * @return \Illuminate\Database\Eloquent\Collection
     */
    protected function selectAll()
    {
        return $this->newQuery()
            ->orderBy('parent_id', 'asc')
            ->orderBy('sort', 'asc')
            ->get();
    }
}
